module extraepd.ptrstack;
import expd.istack;
import std.stdio;
struct ptr_n ( T, int N ) {
  T[N]  pay;
  ptr_n! ( T, N )  *next;
}
//Unknown scary bug attacks this
/*
int a,b,g;
    a = 90;
    b= 70;
    g =67;
    PtrStack!(int) asdf = new PtrStack!(int)();
    asdf.push(g);
    asdf.push(a);
    asdf.push(b);
    writeln(asdf.pop());
    writeln(asdf.pop());
    writeln(asdf.pop());*/
class PtrStack ( T ) {
    enum size = 3;
    alias ptr_n! ( T, size ) Ptr;
    Ptr *base;
    size_t ptr1, ptr2;

    this() {
      base = &Ptr();
    }

    void push ( T pa ) {
      if ( ptr2 < size ) {
          base.pay[ptr2] = pa;
          ptr2++;
        }
      else {
          auto g = &Ptr();
          g.next = base;
          base = g;
          base.pay[0] = pa;
          ptr2 = 1;
        }

      writeln ( base.pay );
    }

    T pop() {
      if ( ptr2 == 0 ) {
          ptr2 = size - 1;
          base = base.next;
        }
      else {
          ptr2--;
        }

      return base.pay[ptr2];
    }

    T peek() {
      return base.pay[ptr2-1];
    }
}
